import { useState, useCallback } from 'react';

/**
 * Dialog Hook
 * 用于管理表单对话框
 */
export const useDialog = () => {
  const [dialogState, setDialogState] = useState(null);

  const showDialog = useCallback(({
    title = '输入',
    message = '',
    fields = [],
    confirmText = '确认',
    cancelText = '取消'
  }) => {
    return new Promise((resolve) => {
      setDialogState({
        title,
        message,
        fields,
        confirmText,
        cancelText,
        onConfirm: (values) => {
          setDialogState(null);
          resolve(values);
        },
        onCancel: () => {
          setDialogState(null);
          resolve(null);
        }
      });
    });
  }, []);

  return {
    dialogState,
    showDialog
  };
};

